package com.jiangyifen.robot.sdk.response;

public class BaseResponse<T> {

	private String id = "";

	private String errCode;
	private String errMsg;

	private T body;

	/**
	 * only for fastjson
	 * you will never call this constructor
	 */
	public BaseResponse() {
	}

	private BaseResponse(String id, T body) {
		setId(id);
		setBody(body);
	}

	public static <T> BaseResponse<T> SUCCESS(String id, T body){
		BaseResponse<T> response = new BaseResponse<>(id, body);
		response.setErrCode("0");
		response.setErrMsg("success");
		return response;
	}
	
	public static <T> BaseResponse<T> FAIL(String id, T body, String errCode, String errMsg){
		BaseResponse<T> response = new BaseResponse<>(id, body);
		response.setErrCode(errCode);
		response.setErrMsg(errMsg);
		return response;
	}
	
	public static <T> BaseResponse<T> FAIL(String id, T body){
		return FAIL(id,body,"-1", "unknow error");
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getErrCode() {
		return errCode;
	}

	public void setErrCode(String errCode) {
		this.errCode = errCode;
	}

	public String getErrMsg() {
		return errMsg;
	}

	public void setErrMsg(String errMsg) {
		this.errMsg = errMsg;
	}

	public T getBody() {
		return body;
	}

	public void setBody(T body) {
		this.body = body;
	}

}
